﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Text;

namespace Bussiness_Objects
{
    /// <summary>
    /// Thong tin table Sach
    /// ----SACH(MaSach,MaDauSach,NhaXuatBan,NamXuatBan,SoLuong,GiaTien)
    /// </summary>
    public class Sach : BusinessObjects
    {
        public Sach()
        {
            MaSach = 0;
            MaDauSach = 0;
            NhaXuatBan = null;
            NamXuatBan = 0;
            SoLuong = 0;
            GiaTien = 0;
        }

        public Sach(int _maSach, int _maDauSach, string _nhaXB, int _namXB, int _soLuong, int _giaTien)
        {
            MaSach = _maSach;
            MaDauSach = _maDauSach;
            NhaXuatBan = _nhaXB;
            NamXuatBan = _namXB;
            SoLuong = _soLuong;
            GiaTien = _giaTien;           
        }

        public void SetParameterSelectID()
        {
            parms = new object[1];
            SqlParameter _parm = new SqlParameter(parMaSach, MaSach);
            parms[0] = _parm;
        }

        public override void SetParameterUpdate()
        {
            parms = new object[6];
            SqlParameter _param = new SqlParameter(parMaDauSach, MaDauSach);
            parms[0] = _param;

            _param = new SqlParameter(parMaSach, MaSach);
            parms[1] = _param;

            _param = new SqlParameter(parNhaXuatBan, NhaXuatBan);
            parms[2] = _param;

            _param = new SqlParameter(parNamXuatBan, NamXuatBan);
            parms[3] = _param;

            _param = new SqlParameter(parSoLuong, SoLuong);
            parms[4] = _param;

            _param = new SqlParameter(parGiaTien, GiaTien);
            parms[5] = _param;
        }
        
        public override void SetParameterInsert()
        {            
            parms = new object[6];
            SqlParameter _param = new SqlParameter(parMaDauSach, MaDauSach);
            parms[0] = _param;

            _param = new SqlParameter(parNhaXuatBan, NhaXuatBan);
            parms[1] = _param;

            _param = new SqlParameter(parNamXuatBan, NamXuatBan);
            parms[2] = _param;

            _param = new SqlParameter(parSoLuong, SoLuong);
            parms[3] = _param;

            _param = new SqlParameter(parGiaTien, GiaTien);
            parms[4] = _param;

            _param = new SqlParameter();
            _param.ParameterName = parMaSach;
            _param.SqlDbType = SqlDbType.Int;
            _param.Direction = ParameterDirection.Output;
            parms[5] = _param;
        }

        public int MaSach { get; set; }
        private const string parMaSach = "@MaSach";        

        public int MaDauSach { get; set; }
        private const string parMaDauSach = "@MaDauSach";

        public string NhaXuatBan { get; set; }
        private const string parNhaXuatBan = "@NhaXuatBan";

        public int NamXuatBan { get; set; }
        private const string parNamXuatBan = "@NamXuatBan";

        public int SoLuong { get; set; }
        private const string parSoLuong = "@SoLuong";

        public int GiaTien { get; set; }
        private const string parGiaTien = "@GiaTien";
    }
}
